package com.zxl.live.screen.screen.ui.widget.panel.heart;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;


public class Petal {
	
	public float stretchA;
	
	public float stretchB;
	
	public float startAngle;
	
	public float angle;
	
	public float growFactor;
	
	public Bloom bloom;

	public float r;

	private Path path = new Path();

	public Petal(float stretchA, float stretchB, float startAngle, float angle, float growFactor, Bloom bloom) {
		this.stretchA = stretchA;
		this.stretchB = stretchB;
		this.startAngle = startAngle;
		this.angle = angle;
		this.growFactor = growFactor;
		this.bloom = bloom;
		this.r = 1;
	}

	public void render(Canvas canvas, Paint paint, int alpha) {
		if (this.r <= this.bloom.r) {
            this.r += this.growFactor; // / 10;
        }
		this.draw(canvas, paint, alpha);
	}

	private void draw(Canvas canvas, Paint paint, int alpha) {
		 Vector v1, v2, v3, v4;
         v1 = new Vector(0, this.r).rotate(Garden.degrad(this.startAngle));
         v2 = v1.clone().rotate(Garden.degrad(this.angle));
         v3 = v1.clone().mult(this.stretchA); //.rotate(this.tanAngleA);
         v4 = v2.clone().mult(this.stretchB); //.rotate(this.tanAngleB);
         path.reset();
         path.moveTo(v1.x, v1.y);
         path.rQuadTo(v3.x, v3.y, v4.x, v4.y);
         path.rLineTo(v2.x, v2.y);
         paint.setAlpha(alpha);
         canvas.drawPath(path, paint);
	}
}
